import { fromJS } from 'immutable';
import * as constants from './constants';

const user = localStorage.getItem('user');
const autoLogin = localStorage.getItem('autoLogin');

const defaultStore = fromJS({
  loginStatus: user ?  user.loginStatus : null,
  autoLogin: autoLogin ? autoLogin : false,
});

export default (state = defaultStore, action) => {
  switch(action.type) {
    case constants.CHANGE_LOGIN_STATUS:
      return state.set('loginStatus', action.status);
    default:
      return state;
  }
}